package clientes;

import static org.junit.Assert.*;

import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;

import static org.mockito.Mockito.*;

public class TestCtaCte {

	Cliente cliente;
	CtaCtePesos ctaCteEnPesos;

	@Before
	public void setUp() throws Exception {

		cliente = mock(Cliente.class);
		ctaCteEnPesos = new CtaCtePesos(100D, cliente);

	}

	@Test
	public void testQueElClienteResponsableEsElMismoQueSePasaCuandoSeCreaElConstructor() {

		assertEquals(cliente, ctaCteEnPesos.clienteResponsable());
	}

	@Test
	public void testLaCuentaSeCreaConUnSaldoPositivo() {

		assertTrue(ctaCteEnPesos.saldoActual() > 0);

	}

	@Test
	public void testLaCtaCorrienteEnPesosPagaUnProductoEspecifico()
			throws ElSaldoDeLaCtaCteEsInsuficienteExeption {

		ctaCteEnPesos.debitar(10D);

		assertTrue(ctaCteEnPesos.saldoActual() == 100D - 10D);

	}

	@Test(expected = ElSaldoDeLaCtaCteEsInsuficienteExeption.class)
	public void testSiQuieroDebitarAlgoQueEsMasCaroDeLoQuePoseeLaCtaCteEnMontoSeArrojaUnaExepcion()
			throws ElSaldoDeLaCtaCteEsInsuficienteExeption {

		ctaCteEnPesos.debitar(120D);

	}

	@Test
	public void testAlPedirLosMontosAnterioresAUnaFechaRetornaUnMapConteniendoLasCoincidenciasDeClaveValor()
			throws ElSaldoDeLaCtaCteEsInsuficienteExeption, InterruptedException{

		ctaCteEnPesos.debitar(12D);
		Thread.sleep(1000);
		ctaCteEnPesos.debitar(39D);

		
		assertTrue(ctaCteEnPesos.detalleAnteriorA(new DateTime(2015, 10, 9, 12, 12)).size() == 2);
		assertTrue(DateTime.now().isBefore(new DateTime(2015, 10, 9, 12, 12)));
	}
	
	
	
	
	@Test
	public void testAlPedirLosMontosPosterioresAUnaFechaRetornaUnMapConteniendoLasCoincidenciasDeClaveValor()
			throws ElSaldoDeLaCtaCteEsInsuficienteExeption, InterruptedException {

		ctaCteEnPesos.debitar(12D);
		Thread.sleep(1000);
		ctaCteEnPesos.debitar(10D);
		
		assertTrue(ctaCteEnPesos.detallePosteriorA(new DateTime(2012, 10, 9, 12, 12)).size() == 2);
		
		assertTrue(DateTime.now().isAfter(new DateTime(2012, 10, 9, 12, 12)));
	}
	
	

}
